


#pragma once


#include "CxType.h"
#include <vector>
#include <boost/signals2.hpp>
#include <boost/typeof/typeof.hpp>


BEGIN_NAMESPACE (MSG_SIGN)

using std::vector;

class CxUnitBulb
{
public:
	typedef  void		(*BulbCallBack)(bool);

public:
	CxUnitBulb():b_isbug(false),b_islight(false),b_islose(false),fn_callback(NULL){}
	~CxUnitBulb(){}

public:
	void		turnOn()
	{
		b_islight=true;
		if(fn_callback!=NULL)
			fn_callback(true);
	}
	void		turnOff()
	{
		b_islight=false;
		if(fn_callback!=NULL)
			fn_callback(false);
	}

	void	loseEff()
	{
		b_islose=true;
	}
	void		resumeEff()
	{
		b_islose=false;
	}

	void		setBug()
	{
		b_isbug=true;
	}
	void		resumeBug()
	{
		b_isbug=false;
	}

	bool		isLight()const{return b_islight;}
	bool		isBug()const{return  b_isbug;}
	bool		isLose()const{return b_islose;}

	void		registCallback(BulbCallBack fn){fn_callback=fn;}

private:

	bool			b_isbug;
	bool			b_islight;
	bool			b_islose;
	BulbCallBack	fn_callback;
};


class CxBulb
{
	typedef		vector< vector < CxUnitBulb * > >		_UnitBulb;
	typedef		void								(*BulbCallBack)(bool);


public:
	CxBulb(int  cx=8,int  cy=8):m_cx(cx),m_cy(cy),m_unitbulb(m_cy)
	{
		buildPart();
	}

	~CxBulb();

public:

	void		registCallback(int x,int y,BulbCallBack fn)
	{
		m_unitbulb.at(x).at(y)->registCallback(fn);
	}
	CxUnitBulb		*getBulb(	int x, int y)
	{
		try
		{
			return	m_unitbulb.at(x).at(y);
		}
		catch(std::exception &)
		{
			CX_ERR_MESSAGE("STDERROR")
			return NULL;
		}
	}
private:

	void							buildPart()
	{
		for(BOOST_AUTO(i,m_unitbulb.begin());i!=m_unitbulb.end();++i)
		{
			for(BOOST_AUTO(j,i->begin());j!=i->end();++j)
				*j=new CxUnitBulb;
		}
	}

private:

	int									m_cx,m_cy;
	_UnitBulb							m_unitbulb;
};


END_NAMESPACE